do_api_query: Reset session on ConnectionError to fix stale connections#913
Open
shawntru04 wants to merge 4 commits intozulip:mainfrom
Open
do_api_query: Reset session on ConnectionError to fix stale connections#913shawntru04 wants to merge 4 commits intozulip:mainfrom
shawntru04 wants to merge 4 commits intozulip:mainfrom
Conversation
When a network middlebox silently drops an idle TCP connection, the next request raises a ConnectionError. Previously the retry logic would reuse the same dead session, failing up to 10 times. Now we close and null out the session on ConnectionError so ensure_session() creates a fresh one on the next retry. Fixes zulip#761.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a network middlebox silently drops an idle TCP connection, the next request raises a ConnectionError. Previously the retry logic would reuse the same dead session, failing up to 10 times. Now we close and null out the session on ConnectionError so ensure_session() creates a fresh one on the next retry.
This differs from #854 in that it reuses the existing error_retry machinery rather than adding a parallel retry system with separate timeout constants and retry counters.
Fixes: #761
How did you test this PR?
Added a new automated test in zulip/tests/test_do_api_query.py that simulates a stale connection by having the first session raise a ConnectionError, then verifies that the session is closed and replaced with a fresh one, and that the request succeeds on retry.
(variable names, code reuse, readability, etc.).
Communicate decisions, questions, and potential concerns.
Individual commits are ready for review (see commit discipline).
Completed manual review and testing of the following: